package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Fans;
import cn.wolfcode.wolf2w.domain.UserInfo;
import cn.wolfcode.wolf2w.query.FansQuery;
import cn.wolfcode.wolf2w.service.IFansService;
import cn.wolfcode.wolf2w.service.IUserInfoService;
import cn.wolfcode.wolf2w.util.JsonResult;
import cn.wolfcode.wolf2w.util.UserParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 关注粉丝控制层
 */
@Controller
@RequestMapping("fans")
public class FansController {

    @Autowired
    private IFansService fansService;
    @Autowired
    private IUserInfoService userInfoService;

    @RequestMapping("/get")
    @ResponseBody
    public Object get(@UserParam UserInfo userInfo, String uid ) {
        List<UserInfo> list = new ArrayList<>();
        Fans fans = fansService.getByuid(uid);
        List<String> followids = fans.getFollowid();
        for (String followid : followids) {
            list.add(userInfoService.get(followid));
        }

        return JsonResult.success(list);
    }
    @RequestMapping("/get2")
    @ResponseBody
    public Object get2(String uid) {
        List<UserInfo> list = new ArrayList<>();
        Fans fans = fansService.getByuid(uid);
        List<String> fansids = fans.getFanid();
        for (String fan : fansids) {
            list.add(userInfoService.get(fan));
        }
        return JsonResult.success(list);
    }

}
